<?php

/*
	Class: Communitas_Integrate_Model_Catalog_Store_Api

	About: Authors
		Tyler Vigeant

	About: License
		<http://communit.as/docs/license>
*/
class Communitas_Integrate_Model_Catalog_Store_Api extends Mage_Catalog_Model_Product_Api {

	public function __construct() {
		parent::__construct();
	}

	public function getStores() {
		$collection = Mage::getModel('core/store')->getCollection();
		
		$stores = array();
		foreach( $collection as $store ){
			$stores[ $store->getCode() ] = $store->getName();
		}
		
		return $stores;
	}
	
	public function getRootCategoryId($storeId) {
		$store = Mage::getModel('core/store')->load($storeId);
		return $store->getRootCategoryId();
	}
	
	public function setRootCategoryId($storeId, $rootCategoryId) {
		$store = Mage::getModel('core/store')->load($storeId);
		$group_id = $store->getGroupId();
		
		$groupModel = Mage::getModel('core/store_group')->load( $group_id );
		$groupModel->setRootCategoryId( $rootCategoryId );
		$saved = $groupModel->save();
		
		Mage::dispatchEvent('store_group_save', array('group' => $groupModel));
		
		return $rootCategoryId;
	}
}
